home *** CD-ROM | disk | FTP | other *** search
- package java.beans;
-
- import java.lang.reflect.Method;
-
- public class PropertyDescriptor extends FeatureDescriptor {
- private Class propertyType;
- private Method readMethod;
- private Method writeMethod;
- private boolean bound;
- private boolean constrained;
- private Class propertyEditorClass;
-
- PropertyDescriptor(PropertyDescriptor x, PropertyDescriptor y) {
- super(x, y);
- this.readMethod = x.readMethod;
- this.propertyType = x.propertyType;
- if (y.readMethod != null) {
- this.readMethod = y.readMethod;
- }
-
- this.writeMethod = x.writeMethod;
- if (y.writeMethod != null) {
- this.writeMethod = y.writeMethod;
- }
-
- this.propertyEditorClass = x.propertyEditorClass;
- if (y.propertyEditorClass != null) {
- this.propertyEditorClass = y.propertyEditorClass;
- }
-
- this.bound = x.bound | y.bound;
- this.constrained = x.constrained | y.constrained;
-
- try {
- this.findPropertyType();
- } catch (IntrospectionException var3) {
- throw new Error("PropertyDescriptor: internal error while merging PDs");
- }
- }
-
- public PropertyDescriptor(String propertyName, Class beanClass) throws IntrospectionException {
- ((FeatureDescriptor)this).setName(propertyName);
- String base = this.capitalize(propertyName);
- this.writeMethod = Introspector.findMethod(beanClass, "set" + base, 1);
- if (this.writeMethod.getParameterTypes()[0] == Boolean.TYPE) {
- try {
- this.readMethod = Introspector.findMethod(beanClass, "is" + base, 0);
- } catch (Exception var4) {
- }
- }
-
- if (this.readMethod == null) {
- this.readMethod = Introspector.findMethod(beanClass, "get" + base, 0);
- }
-
- this.findPropertyType();
- }
-
- public PropertyDescriptor(String propertyName, Class beanClass, String getterName, String setterName) throws IntrospectionException {
- ((FeatureDescriptor)this).setName(propertyName);
- this.readMethod = Introspector.findMethod(beanClass, getterName, 0);
- this.writeMethod = Introspector.findMethod(beanClass, setterName, 1);
- this.findPropertyType();
- }
-
- public PropertyDescriptor(String propertyName, Method getter, Method setter) throws IntrospectionException {
- ((FeatureDescriptor)this).setName(propertyName);
- this.readMethod = getter;
- this.writeMethod = setter;
- this.findPropertyType();
- }
-
- private String capitalize(String s) {
- char[] chars = s.toCharArray();
- chars[0] = Character.toUpperCase(chars[0]);
- return new String(chars);
- }
-
- private void findPropertyType() throws IntrospectionException {
- try {
- this.propertyType = null;
- if (this.readMethod != null) {
- if (this.readMethod.getParameterTypes().length != 0) {
- throw new IntrospectionException("bad read method arg count");
- }
-
- this.propertyType = this.readMethod.getReturnType();
- if (this.propertyType == Void.TYPE) {
- throw new IntrospectionException("read method " + this.readMethod.getName() + " returns void");
- }
- }
-
- if (this.writeMethod != null) {
- Class[] params = this.writeMethod.getParameterTypes();
- if (params.length != 1) {
- throw new IntrospectionException("bad write method arg count");
- }
-
- if (this.propertyType != null && this.propertyType != params[0]) {
- throw new IntrospectionException("type mismatch between read and write methods");
- }
-
- this.propertyType = params[0];
- }
-
- } catch (IntrospectionException var2) {
- throw var2;
- }
- }
-
- public Class getPropertyEditorClass() {
- return this.propertyEditorClass;
- }
-
- public Class getPropertyType() {
- return this.propertyType;
- }
-
- public Method getReadMethod() {
- return this.readMethod;
- }
-
- public Method getWriteMethod() {
- return this.writeMethod;
- }
-
- public boolean isBound() {
- return this.bound;
- }
-
- public boolean isConstrained() {
- return this.constrained;
- }
-
- public void setBound(boolean bound) {
- this.bound = bound;
- }
-
- public void setConstrained(boolean constrained) {
- this.constrained = constrained;
- }
-
- public void setPropertyEditorClass(Class propertyEditorClass) {
- this.propertyEditorClass = propertyEditorClass;
- }
- }
-